# -*- python -*-
# ex: set syntax=python:

# This is a sample buildmaster config file. It must be installed as
# 'master.cfg' in your buildmaster's base directory (although the filename
# can be changed with the --basedir option to 'mktap buildbot master').

# It has one job: define a dictionary named BuildmasterConfig. This
# dictionary has a variety of keys to control different aspects of the
# buildmaster. They are documented in docs/config.xhtml .

# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}
c['schedulers'] = []
c['builders'] = []

####### BUILDSLAVES

# the 'slaves' list defines the set of allowable buildslaves. Each element is
# a BuildSlave object, which is created with bot-name, bot-password.  These
# correspond to values given to the buildslave's mktap invocation.
from buildbot.buildslave import BuildSlave
c['slaves'] = [BuildSlave("D630-laptop", "123456", max_builds=1)]

# 'slavePortnum' defines the TCP port to listen on. This must match the value
# configured into the buildslaves (with their --master option)
c['slavePortnum'] = 9989

####### CHANGESOURCES

# the 'change_source' setting tells the buildmaster how it should find out
# about source code changes. Any class which implements IChangeSource can be
# put here: there are several in buildbot/changes/*.py to choose from.

#from buildbot.changes.pb import PBChangeSource
#c['change_source'] = PBChangeSource()

####### SCHEDULERS

import copy
from buildbot.process              import factory
from buildbot.steps.shell          import Compile, ShellCommand 
from buildbot.steps                import source

defaultenv = {}

def bbot_build_oe_target(factory, target):
    factory.addStep(ShellCommand, 
		description=["Building", defaultenv['MACHINE'], target], 
		command=["/opt/usr/bin/full-oe-autobuild", target], 
		env=copy.copy(defaultenv), 
		timeout=10000)

def bbot_initialize_factory(factory, 
		clean_tmp=False, 
		repository="git://git.openembedded.net/openembedded", 
		branch="org.openembedded.dev"):
    factory.addStep(source.Git(repourl=repository, branch=branch, mode='update'))

    if clean_tmp:
            factory.addStep(ShellCommand, 
		description=["Cleaning", "tmp"],  
		command="/bin/rm tmp || /bin/true", 
		timeout=600)
    else:
            factory.addStep(ShellCommand, 
		description=["Cleaning", "previous", "targets"],  
		command="/bin/rm tmp/deploy/*/images/*/*rootfs* || /bin/true", 
		timeout=600)
            factory.addStep(ShellCommand, 
		description=["Cleaning", "previous", "targets", "step 2"],  
		command="/bin/rm -rf tmp/deploy/*/images/*/*testlab* || /bin/true", 
		timeout=600)

targets   = ['base-image']

## configure the Schedulers
##################################################################################
# micro distribution weekly building
##################################################################################
from buildbot.scheduler import Nightly
c['schedulers'].append(Nightly(name="micro distribution weekly build",
                                 hour=0, minute=0, dayOfWeek=[5],
                                 builderNames=["micro_glibc_qemux86_weekly_build",
					       "micro_glibc_qemumips_weekly_build",
					       "micro_glibc_qemuarm_weekly_build",
					       "micro_eglibc_qemux86_weekly_build",
					       "micro_eglibc_qemumips_weekly_build",
					       "micro_eglibc_qemuarm_weekly_build",
					       "micro_uclibc_qemux86_weekly_build",
					       "micro_uclibc_qemumips_weekly_build",
					       "micro_uclibc_qemuarm_weekly_build",
					],
				 ))

defaultenv['DISTRO'] = 'micro'

defaultenv['LIBC'] = 'glibc'

defaultenv['MACHINE'] = 'qemux86'
micro_glibc_qemux86_weekly_build = factory.BuildFactory()
bbot_initialize_factory(micro_glibc_qemux86_weekly_build, True)
for target in targets:
	bbot_build_oe_target(micro_glibc_qemux86_weekly_build, target)

defaultenv['MACHINE'] = 'qemumips'
micro_glibc_qemumips_weekly_build = factory.BuildFactory()
bbot_initialize_factory(micro_glibc_qemumips_weekly_build, True)
for target in targets:
	bbot_build_oe_target(micro_glibc_qemumips_weekly_build, target)

defaultenv['MACHINE'] = 'qemuarm'
micro_glibc_qemuarm_weekly_build = factory.BuildFactory()
bbot_initialize_factory(micro_glibc_qemuarm_weekly_build, True)
for target in targets:
	bbot_build_oe_target(micro_glibc_qemuarm_weekly_build, target)

defaultenv['LIBC'] = 'eglibc'

defaultenv['MACHINE'] = 'qemux86'
micro_eglibc_qemux86_weekly_build = factory.BuildFactory()
bbot_initialize_factory(micro_eglibc_qemux86_weekly_build, True)
for target in targets:
	bbot_build_oe_target(micro_eglibc_qemux86_weekly_build, target)

defaultenv['MACHINE'] = 'qemumips'
micro_eglibc_qemumips_weekly_build = factory.BuildFactory()
bbot_initialize_factory(micro_eglibc_qemumips_weekly_build, True)
for target in targets:
	bbot_build_oe_target(micro_eglibc_qemumips_weekly_build, target)

defaultenv['MACHINE'] = 'qemuarm'
micro_eglibc_qemuarm_weekly_build = factory.BuildFactory()
bbot_initialize_factory(micro_eglibc_qemuarm_weekly_build, True)
for target in targets:
	bbot_build_oe_target(micro_eglibc_qemuarm_weekly_build, target)

defaultenv['LIBC'] = 'uclibc'

defaultenv['MACHINE'] = 'qemux86'
micro_uclibc_qemux86_weekly_build = factory.BuildFactory()
bbot_initialize_factory(micro_uclibc_qemux86_weekly_build, True)
for target in targets:
	bbot_build_oe_target(micro_uclibc_qemux86_weekly_build, target)

defaultenv['MACHINE'] = 'qemumips'
micro_uclibc_qemumips_weekly_build = factory.BuildFactory()
bbot_initialize_factory(micro_uclibc_qemumips_weekly_build, True)
for target in targets:
	bbot_build_oe_target(micro_uclibc_qemumips_weekly_build, target)

defaultenv['MACHINE'] = 'qemuarm'
micro_uclibc_qemuarm_weekly_build = factory.BuildFactory()
bbot_initialize_factory(micro_uclibc_qemuarm_weekly_build, True)
for target in targets:
	bbot_build_oe_target(micro_uclibc_qemuarm_weekly_build, target)


build_micro_qemux86_gf = {
        'name':      "micro_glibc_qemux86_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "micro_glibc_qemux86_weekly_build",
        'factory':    micro_glibc_qemux86_weekly_build,
}
build_micro_qemumips_gf = {
        'name':      "micro_glibc_qemumips_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "micro_glibc_qemumips_weekly_build",
        'factory':    micro_glibc_qemumips_weekly_build,
}
build_micro_qemuarm_gf = {
        'name':      "micro_glibc_qemuarm_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "micro_glibc_qemuarm_weekly_build",
        'factory':    micro_glibc_qemuarm_weekly_build,
}

build_micro_qemux86_ef = {
        'name':      "micro_eglibc_qemux86_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "micro_eglibc_qemux86_weekly_build",
        'factory':    micro_eglibc_qemux86_weekly_build,
}
build_micro_qemumips_ef = {
        'name':      "micro_eglibc_qemumips_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "micro_eglibc_qemumips_weekly_build",
        'factory':    micro_eglibc_qemumips_weekly_build,
}
build_micro_qemuarm_ef = {
        'name':      "micro_eglibc_qemuarm_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "micro_eglibc_qemuarm_weekly_build",
        'factory':    micro_eglibc_qemuarm_weekly_build,
}

build_micro_qemux86_uf = {
        'name':      "micro_uclibc_qemux86_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "micro_uclibc_qemux86_weekly_build",
        'factory':    micro_uclibc_qemux86_weekly_build,
}
build_micro_qemumips_uf = {
        'name':      "micro_uclibc_qemumips_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "micro_uclibc_qemumips_weekly_build",
        'factory':    micro_uclibc_qemumips_weekly_build,
}
build_micro_qemuarm_uf = {
        'name':      "micro_uclibc_qemuarm_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "micro_uclibc_qemuarm_weekly_build",
        'factory':    micro_uclibc_qemuarm_weekly_build,
}

c['builders'] += [build_micro_qemux86_gf, build_micro_qemumips_gf, build_micro_qemuarm_gf ]
c['builders'] += [build_micro_qemux86_ef, build_micro_qemumips_ef, build_micro_qemuarm_ef ]
c['builders'] += [build_micro_qemux86_uf, build_micro_qemumips_uf, build_micro_qemuarm_uf ]

##################################################################################
# minimal distribution weekly building
##################################################################################
from buildbot.scheduler import Nightly
c['schedulers'].append(Nightly(name="minimal distribution weekly build",
                                 hour=0, minute=0, dayOfWeek=[5],
                                 builderNames=["minimal_glibc_qemux86_weekly_build",
					       "minimal_glibc_qemumips_weekly_build",
					       "minimal_glibc_qemuarm_weekly_build",
					       "minimal_eglibc_qemux86_weekly_build",
					       "minimal_eglibc_qemumips_weekly_build",
					       "minimal_eglibc_qemuarm_weekly_build",
					       "minimal_uclibc_qemux86_weekly_build",
					       "minimal_uclibc_qemumips_weekly_build",
					       "minimal_uclibc_qemuarm_weekly_build",
					],
				 ))

defaultenv['DISTRO'] = 'minimal'

defaultenv['LIBC'] = 'glibc'

defaultenv['MACHINE'] = 'qemux86'
minimal_glibc_qemux86_weekly_build = factory.BuildFactory()
bbot_initialize_factory(minimal_glibc_qemux86_weekly_build, True)
for target in targets:
	bbot_build_oe_target(minimal_glibc_qemux86_weekly_build, target)

defaultenv['MACHINE'] = 'qemumips'
minimal_glibc_qemumips_weekly_build = factory.BuildFactory()
bbot_initialize_factory(minimal_glibc_qemumips_weekly_build, True)
for target in targets:
	bbot_build_oe_target(minimal_glibc_qemumips_weekly_build, target)

defaultenv['MACHINE'] = 'qemuarm'
minimal_glibc_qemuarm_weekly_build = factory.BuildFactory()
bbot_initialize_factory(minimal_glibc_qemuarm_weekly_build, True)
for target in targets:
	bbot_build_oe_target(minimal_glibc_qemuarm_weekly_build, target)

defaultenv['LIBC'] = 'eglibc'

defaultenv['MACHINE'] = 'qemux86'
minimal_eglibc_qemux86_weekly_build = factory.BuildFactory()
bbot_initialize_factory(minimal_eglibc_qemux86_weekly_build, True)
for target in targets:
	bbot_build_oe_target(minimal_eglibc_qemux86_weekly_build, target)

defaultenv['MACHINE'] = 'qemumips'
minimal_eglibc_qemumips_weekly_build = factory.BuildFactory()
bbot_initialize_factory(minimal_eglibc_qemumips_weekly_build, True)
for target in targets:
	bbot_build_oe_target(minimal_eglibc_qemumips_weekly_build, target)

defaultenv['MACHINE'] = 'qemuarm'
minimal_eglibc_qemuarm_weekly_build = factory.BuildFactory()
bbot_initialize_factory(minimal_eglibc_qemuarm_weekly_build, True)
for target in targets:
	bbot_build_oe_target(minimal_eglibc_qemuarm_weekly_build, target)

defaultenv['LIBC'] = 'uclibc'

defaultenv['MACHINE'] = 'qemux86'
minimal_uclibc_qemux86_weekly_build = factory.BuildFactory()
bbot_initialize_factory(minimal_uclibc_qemux86_weekly_build, True)
for target in targets:
	bbot_build_oe_target(minimal_uclibc_qemux86_weekly_build, target)

defaultenv['MACHINE'] = 'qemumips'
minimal_uclibc_qemumips_weekly_build = factory.BuildFactory()
bbot_initialize_factory(minimal_uclibc_qemumips_weekly_build, True)
for target in targets:
	bbot_build_oe_target(minimal_uclibc_qemumips_weekly_build, target)

defaultenv['MACHINE'] = 'qemuarm'
minimal_uclibc_qemuarm_weekly_build = factory.BuildFactory()
bbot_initialize_factory(minimal_uclibc_qemuarm_weekly_build, True)
for target in targets:
	bbot_build_oe_target(minimal_uclibc_qemuarm_weekly_build, target)


build_minimal_qemux86_gf = {
        'name':      "minimal_glibc_qemux86_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "minimal_glibc_qemux86_weekly_build",
        'factory':    minimal_glibc_qemux86_weekly_build,
}
build_minimal_qemumips_gf = {
        'name':      "minimal_glibc_qemumips_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "minimal_glibc_qemumips_weekly_build",
        'factory':    minimal_glibc_qemumips_weekly_build,
}
build_minimal_qemuarm_gf = {
        'name':      "minimal_glibc_qemuarm_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "minimal_glibc_qemuarm_weekly_build",
        'factory':    minimal_glibc_qemuarm_weekly_build,
}

build_minimal_qemux86_ef = {
        'name':      "minimal_eglibc_qemux86_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "minimal_eglibc_qemux86_weekly_build",
        'factory':    minimal_eglibc_qemux86_weekly_build,
}
build_minimal_qemumips_ef = {
        'name':      "minimal_eglibc_qemumips_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "minimal_eglibc_qemumips_weekly_build",
        'factory':    minimal_eglibc_qemumips_weekly_build,
}
build_minimal_qemuarm_ef = {
        'name':      "minimal_eglibc_qemuarm_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "minimal_eglibc_qemuarm_weekly_build",
        'factory':    minimal_eglibc_qemuarm_weekly_build,
}

build_minimal_qemux86_uf = {
        'name':      "minimal_uclibc_qemux86_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "minimal_uclibc_qemux86_weekly_build",
        'factory':    minimal_uclibc_qemux86_weekly_build,
}
build_minimal_qemumips_uf = {
        'name':      "minimal_uclibc_qemumips_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "minimal_uclibc_qemumips_weekly_build",
        'factory':    minimal_uclibc_qemumips_weekly_build,
}
build_minimal_qemuarm_uf = {
        'name':      "minimal_uclibc_qemuarm_weekly_build",
        'slavename': "D630-laptop",
        'builddir':  "minimal_uclibc_qemuarm_weekly_build",
        'factory':    minimal_uclibc_qemuarm_weekly_build,
}

c['builders'] += [build_minimal_qemux86_gf, build_minimal_qemumips_gf, build_minimal_qemuarm_gf ]
c['builders'] += [build_minimal_qemux86_ef, build_minimal_qemumips_ef, build_minimal_qemuarm_ef ]
c['builders'] += [build_minimal_qemux86_uf, build_minimal_qemumips_uf, build_minimal_qemuarm_uf ]

####### STATUS TARGETS

# 'status' is a list of Status Targets. The results of each build will be
# pushed to these targets. buildbot/status/*.py has a variety to choose from,
# including web pages, email senders, and IRC bots.
c['status'] = []

from buildbot.status               import html
c['status'].append(html.WebStatus(http_port=8010, allowForce=True))
c['status'].append(html.WebStatus(http_port=8011, allowForce=False))

"""
from buildbot.status import mail
m = mail.MailNotifier(fromaddr="buildbot@gulessoft.com",
		   extraRecipients=["camelguo@gmail.com",
				"guo.hongruan@gulessoft.com"],
		   sendToInterestedUsers=False)
c['status'].append(m)

from buildbot.status import words
c['status'].append(words.IRC(host="irc.example.com", nick="bb",
			  channels=["#example"]))
"""

####### PROJECT IDENTITY

# the 'projectName' string will be used to describe the project that this
# buildbot is working on. For example, it is used as the title of the
# waterfall HTML page. The 'projectURL' string will be used to provide a link
# from buildbot HTML pages to your project's home page.

c['projectName'] = "Openembedded QA Buildbot"
c['projectURL'] = "http://www.openembedded.org/"

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server (usually the html.Waterfall page) is visible. This
# typically uses the port number set in the Waterfall 'status' entry, but
# with an externally-visible host name which the buildbot cannot figure out
# without some help.

c['buildbotURL'] = "http://localhost:8010/"

####### MEMORY AND DISK USAGE OPTIONS

c['buildHorizon'] = 100
c['eventHorizon'] = 50
c['logHorizon'] = 40

c['buildCacheSize'] = 15

####### DEBUGGING OPTIONS

# if you set 'debugPassword', then you can connect to the buildmaster with
# the diagnostic tool in contrib/debugclient.py . From this tool, you can
# manually force builds and inject changes, which may be useful for testing
# your buildmaster without actually committing changes to your repository (or
# before you have a functioning 'sources' set up). The debug tool uses the
# same port number as the slaves do: 'slavePortnum'.

c['debugPassword'] = "123456"

# if you set 'manhole', you can ssh into the buildmaster and get an
# interactive python shell, which may be useful for debugging buildbot
# internals. It is probably only useful for buildbot developers. You can also
# use an authorized_keys file, or plain telnet.
#from buildbot import manhole
#c['manhole'] = manhole.PasswordManhole("tcp:9999:interface=127.0.0.1",
#                                       "admin", "password")
